package com.renting.modules.medical.web;

import cn.hutool.core.util.RandomUtil;
import com.renting.common.config.HttpStatusConstant;
import com.renting.common.entity.Result;
import com.renting.common.entity.ResultList;
import com.renting.modules.medical.dao.MedicalImageDao;
import com.renting.modules.medical.entity.MedicalImage;
import com.renting.modules.medical.service.MedicalImageService;
import com.renting.modules.renting.rentSys.entity.House;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by Administrator on 2018/5/10.
 */
@RestController
public class MedicalImageController {

    @Autowired
    MedicalImageService medicalImageService;
    @Autowired
    MedicalImageDao medicalImageDao;

    @RequestMapping(value = "v1/medicalImgs", method = RequestMethod.GET)
    @CrossOrigin(origins = "*")
    public String medicalImages() {
        ResultList<MedicalImage> roleResultList = new ResultList<>();
        int total = (int) medicalImageDao.count();
        roleResultList.setTotal(total);
        roleResultList.setData(medicalImageService.medicalImages());
        return roleResultList.toJSONString();
    }


    @RequestMapping(value = "/v1/medicalImgs/one", method = RequestMethod.POST)
    @CrossOrigin(origins = "*")
    public Result addHouse(MedicalImage medicalImage,  MultipartFile file) {
        Result result = new Result(HttpStatusConstant.SUCCESS);
        String id = RandomUtil.simpleUUID();
        medicalImage.setId(id);//生成一个id
        medicalImageService.save(medicalImage, file);
        return result;
    }
}
